#!/usr/bin/python
from Tkinter import *
from tkFileDialog import *
import sys
import en2uk


def do_translation(event):
	print dir(event)

def terminate_program():
	sys.exit()

def openfile():
	fn = askopenfilename()
	text= open(fn,'r').read()
	global text1
	text1.delete(1.0,END)
	text1.insert(END,text)

def translate_en_uk():
	global text1,text2 
	text2.delete(1.0,END)
	text = u"".join(en2uk.translate(text1.get(1.0,END),""))
	print text
	text2.insert(END,text)

root = Tk()
root.title("Translator")

mainmenu=Menu(root)
root.config(menu=mainmenu)
filemenu = Menu(mainmenu)
mainmenu.add_cascade(label="File",menu=filemenu)
filemenu.add_command(label="Open...",command=openfile)
filemenu.add_command(label="Download...")
filemenu.add_command(label="Save...")
filemenu.add_command(label="Exit",command=terminate_program)
translatemenu = Menu(mainmenu)
mainmenu.add_cascade(label="Translate",menu=translatemenu)
translatemenu.add_command(label="en -> uk",command = translate_en_uk)

text1 = Text(root,width=80,height=10,font="Monospace 12")
scr1 = Scrollbar(root,command=text1.yview)
text1.configure(yscrollcommand=scr1.set)
text1.grid(row=0,column=0)
scr1.grid(row=0,column=1)


text2 = Text(root,width=80,font="Monospace 12")
scr2 = Scrollbar(root,command=text2.yview)
text2.configure(yscrollcommand=scr2.set)
text2.grid(row=1,column=0)
scr2.grid(row=1,column=1)

root.mainloop()
